package com.varian.auth.controller;

import com.varian.auth.model.dto.OAuth2RegisteredClientDTO;
import com.varian.auth.model.dto.OAuth2RegisteredClientListDTO;
import com.varian.auth.model.vo.OAuth2RegisteredClientVO;
import com.varian.auth.service.IOAuth2RegisteredClientService;
import com.varian.service.web.BaseController;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.PermitAll;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ben
 * @since 2024/6/27
 */
@PermitAll
@RestController
@RequiredArgsConstructor
@Tag(name = "OAuth2客户端控制层")
@RequestMapping("/oauth2/registered-client")
public class OAuth2RegisteredClientController extends BaseController<IOAuth2RegisteredClientService> {

    @PostMapping
    @Operation(summary = "新增OAuth2客户端")
    public IR add(@Validated @RequestBody OAuth2RegisteredClientDTO dto) {
        return R.status(baseService.add(dto));
    }

    @PutMapping("{id:\\d+}")
    @Operation(summary = "修改OAuth2客户端")
    public IR modify(@Validated @PathVariable("id") Long id, @Validated @RequestBody OAuth2RegisteredClientDTO dto) {
        return R.status(baseService.modify(id, dto));
    }

    @GetMapping("list")
    @Operation(summary = "查询OAuth2客户端列表")
    public R<List<OAuth2RegisteredClientVO>> list(OAuth2RegisteredClientListDTO dto) {
        return R.data(baseService.list(dto));
    }

    @GetMapping("{id:\\d+}")
    @Operation(summary = "查询OAuth2客户端详情")
    public R<OAuth2RegisteredClientVO> detail(@PathVariable("id") Long id) {
        return R.data(baseService.detailById(id));
    }
}
